//
//  MTFeedbackAlertView.swift
//  MT
//
//  Created by 陈悦 on 2020/5/29.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit

@objc
protocol MTFeedbackAlertViewDelegate: NSObjectProtocol {
    /// 选择举报回调
    @objc optional func reportClick()
    
    /// 选择拉黑回调
    @objc optional func blackClick()
}

class MTFeedbackAlertView: UIView {
    @IBOutlet weak var bgViewHeight: NSLayoutConstraint!
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet var contentView: UIView!
    
    /// 代理
    weak var delegate: MTFeedbackAlertViewDelegate?

    @IBAction func reportBtnClick(_ sender: Any) {
        if let delegate = delegate {
            delegate.reportClick?()
        }
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
    }
    
    @IBAction func blackBtnClick(_ sender: Any) {
        if let delegate = delegate {
            delegate.blackClick?()
        }
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
    }
    
    @IBAction func cancelBtnClick(_ sender: Any) {
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (flag) in
            self.removeFromSuperview()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 加载xib
        contentView = (Bundle.main.loadNibNamed("MTFeedbackAlertView", owner: self, options: nil)?.last as! UIView)
        // 设置frame
        contentView.frame = frame
        contentView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        //        NSToolObjectClass.animationWithAlertViewWithView(allView: tipView)
        
        bgView.layer.cornerRadius = 8
        bgViewHeight.constant = 143+ScreenBottomExtraOffset
        
        // 添加上去
        addSubview(contentView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
